package com.pr.makfilm.core.page;

import com.pr.makfilm.core.cmp.authorization.LogoutLink;
import com.pr.makfilm.domain.User;
import com.pr.makfilm.security.service.ISecurityService;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.spring.injection.annot.SpringBean;

import java.io.Serializable;

/**
 * Created by p.radomski on 18.02.14.
 */
public class AbstractPage extends WebPage implements Serializable
{
   @SpringBean
   private ISecurityService securityService;

   protected AbstractPage()
   {
      super();
   }

   protected AbstractPage(PageParameters parameters)
   {
      super(parameters);
   }

   @Override
   protected void onInitialize()
   {
      super.onInitialize();
      User user = securityService.getLoggedInUser();
      String userInfo = "";
      if (user != null)
      {
         userInfo = user.getFirstName() + " " + user.getLastName();
      }
      add(new Label("user.info", userInfo));
      add(new LogoutLink("logout"));
   }
}
